import { CLOUD_BASE_URL } from '../constant/index'
import { get } from '../../../../common/request'
/**
 * 获取随机数
 */
export const getUuid = (len, radix) => {
  let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
  const uuid = []
  let i
  radix = radix || chars.length
  if (len) {
    for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]
  } else {
    let r
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
    uuid[14] = '4'
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | Math.random() * 16
        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]
      }
    }
  }
  return `id--${uuid.join('')}--${new Date().getTime()}`
}
/**
 * 角度转弧度的函数
 * */  
export function degreesToRadians(degrees = 0) {  
  return degrees * (Math.PI / 180)
}  
/**
 * 计算正切值的函数
 */
export function calculateTangent(angleDegrees = 0) {  
  const angleRadians = degreesToRadians(angleDegrees);  
  return Math.tan(angleRadians);  
}  
/**
 * 计算邻边长度的函数
 */
export function calculateAdjacentSide(hypotenuse = 0, angleDegrees = 0) {  
  const angleRadians = degreesToRadians(angleDegrees);  
  return hypotenuse * Math.cos(angleRadians);  
}
/**
 * 计算对边长度的函数
 */
export function calculateOppositeSide(hypotenuse, angleDegrees) {
  const angleRadians = degreesToRadians(angleDegrees);
  return hypotenuse * Math.sin(angleRadians);
}
/**
 * 扩展对象属性
 * @param {*} instance 
 */
export const extendClass = (instance) => {
  typeof instance === 'object' && Object.keys(instance).forEach(key => {
    if (typeof instance[key] !== 'function') {
      const newKey = `set${key[0].toUpperCase()}${key.slice(1)}`
      /**
       * 设置属性方法
       * @param {*} v 
       */
      instance[newKey] = (v) => {
        instance[key] = v
      }
    }
  })
}
/**
 * 判断是否点击到精灵
 */
export const isClickOnSprite = (sprite, x, y) => {
  return x > sprite.x && x < sprite.x + sprite.width && y > sprite.y && y < sprite.y + sprite.height
}
/**
 * 获取云开发资源地址
 */
export const getCloudUrl = (url) => {
  return `${CLOUD_BASE_URL}${url}`
}
  /**
   * 初始化资源
   */
export const initResources = (list) => {
  list.forEach(url => {
  })
}